Brain data
Contents
Brain data#
This section presents results of brain MRI data. Below are quantitative T1 values computed using the MP2RAGE and the MTsat methods. These values are averaged within the gray matter and white matter masks.
Code imports#
# Python imports
from IPython.display import clear_output
from pathlib import Path
import numpy as np
import pandas as pd
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', 1000)
pd.set_option('display.colheader_justify', 'center')
pd.set_option('display.precision', 1)
# Import custom tools
from tools.data import Data
from tools.plot import Plot
from tools.stats import Stats
Download data#
data_type = 'brain'
release_version = 'latest'
dataset = Data(data_type)
dataset.download(release_version)
--2023-01-11 03:11:34-- https://github.com/courtois-neuromod/anat-processing/releases/download/r20220921/neuromod-anat-brain-qmri.zip
Resolving github.com (github.com)... 140.82.113.3
Connecting to github.com (github.com)|140.82.113.3|:443... connected.
HTTP request sent, awaiting response...
302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/333825187/59a68bb3-4423-49ab-959d-247690acbebc?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230111%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230111T031134Z&X-Amz-Expires=300&X-Amz-Signature=629835183c4ae1bcdd9ea442772a09dbb458598221796b03cecdd78949a57cff&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=333825187&response-content-disposition=attachment%3B%20filename%3Dneuromod-anat-brain-qmri.zip&response-content-type=application%2Foctet-stream [following]
--2023-01-11 03:11:34-- https://objects.githubusercontent.com/github-production-release-asset-2e65be/333825187/59a68bb3-4423-49ab-959d-247690acbebc?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230111%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230111T031134Z&X-Amz-Expires=300&X-Amz-Signature=629835183c4ae1bcdd9ea442772a09dbb458598221796b03cecdd78949a57cff&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=333825187&response-content-disposition=attachment%3B%20filename%3Dneuromod-anat-brain-qmri.zip&response-content-type=application%2Foctet-stream
Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.110.133, 185.199.109.133, 185.199.108.133, ...
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.110.133|:443... connected.
HTTP request sent, awaiting response...
Archive: neuromod-anat-brain-qmri.zip
inflating: data/brain/neuromod-anat-brain.nextflow.log
inflating: data/brain/results-neuromod-anat-brain-qmri.csv
inflating: data/brain/._results-neuromod-anat-brain-qmri.csv
inflating: data/brain/dag.dot
inflating: data/brain/report.html
inflating: data/brain/dag.png
200 OK
Length: 1301347 (1.2M) [application/octet-stream]
Saving to: ‘neuromod-anat-brain-qmri.zip’
0K .......... .......... .......... .......... .......... 3% 5.89M 0s
50K .......... .......... .......... .......... .......... 7% 7.22M 0s
100K .......... .......... .......... .......... .......... 11% 61.1M 0s
150K .......... .......... .......... .......... .......... 15% 25.1M 0s
200K .......... .......... .......... .......... .......... 19% 11.5M 0s
250K .......... .......... .......... .......... .......... 23% 78.0M 0s
300K .......... .......... .......... .......... .......... 27% 59.5M 0s
350K .......... .......... .......... .......... .......... 31% 56.0M 0s
400K .......... .......... .......... .......... .......... 35% 48.2M 0s
450K .......... .......... .......... .......... .......... 39% 17.2M 0s
500K .......... .......... .......... .......... .......... 43% 131M 0s
550K .......... .......... .......... .......... .......... 47% 63.0M 0s
600K .......... .......... .......... .......... .......... 51% 288M 0s
650K .......... .......... .......... .......... .......... 55% 101M 0s
700K .......... .......... .......... .......... .......... 59% 128M 0s
750K .......... .......... .......... .......... .......... 62% 125M 0s
800K .......... .......... .......... .......... .......... 66% 101M 0s
850K .......... .......... .......... .......... .......... 70% 145M 0s
900K .......... .......... .......... .......... .......... 74% 206M 0s
950K .......... .......... .......... .......... .......... 78% 170M 0s
1000K .......... .......... .......... .......... .......... 82% 17.4M 0s
1050K .......... .......... .......... .......... .......... 86% 130M 0s
1100K .......... .......... .......... .......... .......... 90% 313M 0s
1150K .......... .......... .......... .......... .......... 94% 276M 0s
1200K .......... .......... .......... .......... .......... 98% 95.7M 0s
1250K .......... .......... 100% 295M=0.04s
2023-01-11 03:11:34 (34.3 MB/s) - ‘neuromod-anat-brain-qmri.zip’ saved [1301347/1301347]
Load data plot it#
qMRI Metrics#
dataset.load()
fig_gm = Plot(dataset, plot_name = 'brain-1')
fig_gm.title = 'Brain qMRI microstructure measures'
# If you're running this notebook in a Jupyter Notebook (eg, on MyBinder), change 'jupyter-book' to 'notebook'
fig_gm.display('jupyter-book')
Statistics#
White Matter#
stats_wm = Stats(dataset)
stats_wm.build_df('WM')
stats_wm.build_stats_table()
display(stats_wm.stats_table)
| T1 (MP2RAGE) | T1 (MTsat) | MTR | MTsat | |
|---|---|---|---|---|
| intrasubject COV mean [%] | 0.6 | 2.3 | 0.6 | 1.7 |
| intrasubject COV std [%] | 0.2 | 0.8 | 0.1 | 0.5 |
| intersubject mean COV [%] | 1.9 | 3.5 | 0.4 | 2.2 |
Grey Matter#
stats_gm = Stats(dataset)
stats_gm.build_df('GM')
stats_gm.build_stats_table()
display(stats_gm.stats_table)
| T1 (MP2RAGE) | T1 (MTsat) | MTR | MTsat | |
|---|---|---|---|---|
| intrasubject COV mean [%] | 0.4 | 3.1 | 0.8 | 2.7 |
| intrasubject COV std [%] | 0.1 | 1.6 | 0.2 | 1.2 |
| intersubject mean COV [%] | 1.0 | 5.7 | 1.2 | 4.5 |
Diffusion Tracts#
data_type = 'brain-diffusion'
release_version = 'latest'
dataset = Data(data_type)
dataset.download(release_version)
dataset.load()
fig_diff = Plot(dataset, plot_name = 'brain-diff')
fig_diff.title = 'Brain qMRI diffusion measures'
fig_diff.display('jupyter-book')
--2023-01-11 03:11:36-- https://github.com/courtois-neuromod/anat-processing/releases/download/r20220921b/brain-diffusion-arnaud.zip
Resolving github.com (github.com)... 140.82.113.3
Connecting to github.com (github.com)|140.82.113.3|:443... connected.
HTTP request sent, awaiting response...
302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/333825187/db2be019-9644-4ff2-8c70-c2d5347090b0?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230111%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230111T031136Z&X-Amz-Expires=300&X-Amz-Signature=4fb651cf0cf389625244c42527998b4559fef113359f82cb30caf27c988c366e&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=333825187&response-content-disposition=attachment%3B%20filename%3Dbrain-diffusion-arnaud.zip&response-content-type=application%2Foctet-stream [following]
--2023-01-11 03:11:36-- https://objects.githubusercontent.com/github-production-release-asset-2e65be/333825187/db2be019-9644-4ff2-8c70-c2d5347090b0?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230111%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230111T031136Z&X-Amz-Expires=300&X-Amz-Signature=4fb651cf0cf389625244c42527998b4559fef113359f82cb30caf27c988c366e&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=333825187&response-content-disposition=attachment%3B%20filename%3Dbrain-diffusion-arnaud.zip&response-content-type=application%2Foctet-stream
Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.109.133, 185.199.111.133, 185.199.110.133, ...
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.109.133|:443... connected.
HTTP request sent, awaiting response...
200 OK
Length: 192601 (188K) [application/octet-stream]
Saving to: ‘brain-diffusion-arnaud.zip’
0K .......... .......... .......... .......... .......... 26% 580K 0s
50K .......... .......... .......... .......... .......... 53% 1.08M 0s
100K .......... .......... .......... .......... .......... 79% 991K 0s
150K .......... .......... .......... ........ 100% 107M=0.2s
2023-01-11 03:11:37 (1.01 MB/s) - ‘brain-diffusion-arnaud.zip’ saved [192601/192601]
Archive: brain-diffusion-arnaud.zip
inflating: data/brain-diffusion/mean_std.json
inflating: data/brain-diffusion/._mean_std.json
inflating: data/brain-diffusion/volumes.json
inflating: data/brain-diffusion/._volumes.json
Statistics#
stats_cc1 = Stats(dataset)
stats_cc1.build_df('CC_1')
stats_cc1.build_stats_table()
display(stats_cc1.stats_table)
| FA (DWI) | MD (DWI) | RD (DWI) | |
|---|---|---|---|
| intrasubject COV mean [%] | 1.0 | 0.8 | 1.1 |
| intrasubject COV std [%] | 0.3 | 0.7 | 0.5 |
| intersubject mean COV [%] | 4.1 | 2.2 | 4.1 |
stats_mcp = Stats(dataset)
stats_mcp.build_df('MCP')
stats_mcp.build_stats_table()
display(stats_mcp.stats_table)
| FA (DWI) | MD (DWI) | RD (DWI) | |
|---|---|---|---|
| intrasubject COV mean [%] | 1.1 | 1.0 | 1.6 |
| intrasubject COV std [%] | 0.4 | 0.3 | 0.4 |
| intersubject mean COV [%] | 6.7 | 2.4 | 6.3 |
Diffusion - Corpus Callosum#
data_type = 'brain-diffusion-cc'
release_version = 'latest'
dataset = Data(data_type)
dataset.download(release_version)
dataset.load()
fig_diff = Plot(dataset, plot_name = 'brain-diff-cc')
fig_diff.title = 'Brain qMRI diffusion measures - corpus callosum'
fig_diff.display('jupyter-book')
--2023-01-11 03:11:50-- https://github.com/courtois-neuromod/anat-processing/releases/download/r20230110/brain-diffusion-cc.zip
Resolving github.com (github.com)... 140.82.113.3
Connecting to github.com (github.com)|140.82.113.3|:443... connected.
HTTP request sent, awaiting response...
404 Not Found
2023-01-11 03:11:50 ERROR 404: Not Found.
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of brain-diffusion-cc.zip or
brain-diffusion-cc.zip.zip, and cannot find brain-diffusion-cc.zip.ZIP, period.
Archive: brain-diffusion-cc.zip
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
Cell In[10], line 7
4 dataset = Data(data_type)
5 dataset.download(release_version)
----> 7 dataset.load()
9 fig_diff = Plot(dataset, plot_name = 'brain-diff-cc')
11 fig_diff.title = 'Brain qMRI diffusion measures - corpus callosum'
File ~/work/anat-processing-book/anat-processing-book/source/tools/data.py:142, in Data.load(self)
139 file_path = self.data_dir / data_file
141 # Read data
--> 142 self.data = pd.read_csv(file_path, converters={'project_id': lambda x: str(x)})
144 # Sort data acording to subject and session columns
145 self.data.sort_values(['subject', 'session'], ascending=[True, True])
File /opt/hostedtoolcache/Python/3.8.15/x64/lib/python3.8/site-packages/pandas/util/_decorators.py:311, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs)
305 if len(args) > num_allow_args:
306 warnings.warn(
307 msg.format(arguments=arguments),
308 FutureWarning,
309 stacklevel=stacklevel,
310 )
--> 311 return func(*args, **kwargs)
File /opt/hostedtoolcache/Python/3.8.15/x64/lib/python3.8/site-packages/pandas/io/parsers/readers.py:586, in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, error_bad_lines, warn_bad_lines, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options)
571 kwds_defaults = _refine_defaults_read(
572 dialect,
573 delimiter,
(...)
582 defaults={"delimiter": ","},
583 )
584 kwds.update(kwds_defaults)
--> 586 return _read(filepath_or_buffer, kwds)
File /opt/hostedtoolcache/Python/3.8.15/x64/lib/python3.8/site-packages/pandas/io/parsers/readers.py:482, in _read(filepath_or_buffer, kwds)
479 _validate_names(kwds.get("names", None))
481 # Create the parser.
--> 482 parser = TextFileReader(filepath_or_buffer, **kwds)
484 if chunksize or iterator:
485 return parser
File /opt/hostedtoolcache/Python/3.8.15/x64/lib/python3.8/site-packages/pandas/io/parsers/readers.py:811, in TextFileReader.__init__(self, f, engine, **kwds)
808 if "has_index_names" in kwds:
809 self.options["has_index_names"] = kwds["has_index_names"]
--> 811 self._engine = self._make_engine(self.engine)
File /opt/hostedtoolcache/Python/3.8.15/x64/lib/python3.8/site-packages/pandas/io/parsers/readers.py:1040, in TextFileReader._make_engine(self, engine)
1036 raise ValueError(
1037 f"Unknown engine: {engine} (valid options are {mapping.keys()})"
1038 )
1039 # error: Too many arguments for "ParserBase"
-> 1040 return mapping[engine](self.f, **self.options)
File /opt/hostedtoolcache/Python/3.8.15/x64/lib/python3.8/site-packages/pandas/io/parsers/c_parser_wrapper.py:51, in CParserWrapper.__init__(self, src, **kwds)
48 kwds["usecols"] = self.usecols
50 # open handles
---> 51 self._open_handles(src, kwds)
52 assert self.handles is not None
54 # Have to pass int, would break tests using TextReader directly otherwise :(
File /opt/hostedtoolcache/Python/3.8.15/x64/lib/python3.8/site-packages/pandas/io/parsers/base_parser.py:222, in ParserBase._open_handles(self, src, kwds)
218 def _open_handles(self, src: FilePathOrBuffer, kwds: dict[str, Any]) -> None:
219 """
220 Let the readers open IOHandles after they are done with their potential raises.
221 """
--> 222 self.handles = get_handle(
223 src,
224 "r",
225 encoding=kwds.get("encoding", None),
226 compression=kwds.get("compression", None),
227 memory_map=kwds.get("memory_map", False),
228 storage_options=kwds.get("storage_options", None),
229 errors=kwds.get("encoding_errors", "strict"),
230 )
File /opt/hostedtoolcache/Python/3.8.15/x64/lib/python3.8/site-packages/pandas/io/common.py:702, in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)
697 elif isinstance(handle, str):
698 # Check whether the filename is to be opened in binary mode.
699 # Binary mode does not support 'encoding' and 'newline'.
700 if ioargs.encoding and "b" not in ioargs.mode:
701 # Encoding
--> 702 handle = open(
703 handle,
704 ioargs.mode,
705 encoding=ioargs.encoding,
706 errors=errors,
707 newline="",
708 )
709 else:
710 # Binary mode
711 handle = open(handle, ioargs.mode)
FileNotFoundError: [Errno 2] No such file or directory: 'data/brain-diffusion-cc/corpus_callosum-metrics.csv'
Statistics#
stats_cc1 = Stats(dataset)
stats_cc1.build_df('genu')
stats_cc1.build_stats_table()
display(stats_cc1.stats_table)
stats_cc1 = Stats(dataset)
stats_cc1.build_df('body')
stats_cc1.build_stats_table()
display(stats_cc1.stats_table)
stats_cc1 = Stats(dataset)
stats_cc1.build_df('splenium')
stats_cc1.build_stats_table()
display(stats_cc1.stats_table)